package com.wx.chapter17.threaduse;

/**
 * @Author : 佩萁
 * Description :
 * @Create : 2023/8/16 - 12:03
 */
public class Thread01 {
    public static void main(String[] args) {
        Cat cat = new Cat();
        cat.start();
        System.out.println("主线程继续运行" + Thread.currentThread().getName());
        for (int i = 0; i < 60; i++) {
            System.out.println("主线程i=" + i);
            //让主线程休眠
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

class Cat extends Thread {
    int times = 0;

    @Override
    public void run() {
        while (true) {
            //该线程每隔1秒，在控制台输出 “喵喵,  我是小猫咪”
            System.out.println("喵喵,  我是小猫咪" + (++times) + Thread.currentThread().getName());
            //输出结束后让线程休息1秒
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (times == 80) {
                break;
            }
        }
    }
}